package com.javacommunity.model.entity;

// Generated Nov 25, 2014 11:55:44 PM by Hibernate Tools 3.4.0.CR1

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 *
 * @author Cong Pham Dinh
 */
@Entity
@Table(name = "user", catalog = "db_javadanang", uniqueConstraints = {
    @UniqueConstraint(columnNames = "userName"),
    @UniqueConstraint(columnNames = "email")})
public class User implements java.io.Serializable {

    private Integer userId;
    private Role role;
    private String userName;
    private String pwd;
    private String fullName;
    private Date dayOfBirth;
    private boolean gender;
    private String email;
    private String address;
    private String job;
    private String phoneNumber;
    private String about;
    private String avatarPath;
    private String idActive;
    private boolean active;
    private List<Post> posts = new ArrayList<Post>();
    private List<UserAnswer> userAnswers = new ArrayList<UserAnswer>();
    private List<UserQuestion> userQuestions = new ArrayList<UserQuestion>();
    private List<Answer> answers = new ArrayList<Answer>();
    private List<UserPost> userPosts = new ArrayList<UserPost>();
    private List<Question> questions = new ArrayList<Question>();
    private List<Comment> comments = new ArrayList<Comment>();

    public User() {
    }

    public User(Role role, String userName, String pwd, String fullName,
            boolean gender, String email, boolean active) {
        this.role = role;
        this.userName = userName;
        this.pwd = pwd;
        this.fullName = fullName;
        this.gender = gender;
        this.email = email;
        this.active = active;
    }

    public User(Role role, String userName, String pwd, String fullName,
            Date dayOfBirth, boolean gender, String email, String address,
            String job, String phoneNumber, String about, String avatarPath,
            String idActive, boolean active, List<Post> posts,
            List<UserAnswer> userAnswers, List<UserQuestion> userQuestions,
            List<Answer> answers, List<UserPost> userPosts,
            List<Question> questions, List<Comment> comments) {
        this.role = role;
        this.userName = userName;
        this.pwd = pwd;
        this.fullName = fullName;
        this.dayOfBirth = dayOfBirth;
        this.gender = gender;
        this.email = email;
        this.address = address;
        this.job = job;
        this.phoneNumber = phoneNumber;
        this.about = about;
        this.avatarPath = avatarPath;
        this.idActive = idActive;
        this.active = active;
        this.posts = posts;
        this.userAnswers = userAnswers;
        this.userQuestions = userQuestions;
        this.answers = answers;
        this.userPosts = userPosts;
        this.questions = questions;
        this.comments = comments;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "userId", unique = true, nullable = false)
    public Integer getUserId() {
        return this.userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @Fetch (FetchMode.SELECT)
    @JoinColumn(name = "roleId", nullable = false)
    public Role getRole() {
        return this.role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    @Column(name = "userName", unique = true, nullable = false, length = 32)
    public String getUserName() {
        return this.userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Column(name = "pwd", nullable = false, length = 45)
    public String getPwd() {
        return this.pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    @Column(name = "fullName", nullable = false, length = 45)
    public String getFullName() {
        return this.fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "dayOfBirth", length = 10)
    public Date getDayOfBirth() {
        return this.dayOfBirth;
    }

    public void setDayOfBirth(Date dayOfBirth) {
        this.dayOfBirth = dayOfBirth;
    }

    @Column(name = "gender", nullable = false)
    public boolean isGender() {
        return this.gender;
    }

    public void setGender(boolean gender) {
        this.gender = gender;
    }

    @Column(name = "email", unique = true, nullable = false, length = 45)
    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name = "address", length = 100)
    public String getAddress() {
        return this.address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Column(name = "job", length = 105)
    public String getJob() {
        return this.job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    @Column(name = "phoneNumber", length = 15)
    public String getPhoneNumber() {
        return this.phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    @Column(name = "about", length = 500)
    public String getAbout() {
        return this.about;
    }

    public void setAbout(String about) {
        this.about = about;
    }

    @Column(name = "avatarPath", length = 75)
    public String getAvatarPath() {
        return this.avatarPath;
    }

    public void setAvatarPath(String avatarPath) {
        this.avatarPath = avatarPath;
    }

    @Column(name = "idActive", length = 45)
    public String getIdActive() {
        return this.idActive;
    }

    public void setIdActive(String idActive) {
        this.idActive = idActive;
    }

    @Column(name = "active", nullable = false)
    public boolean isActive() {
        return this.active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "user")
    @Fetch (FetchMode.SELECT)
    public List<Post> getPosts() {
        return this.posts;
    }

    public void setPosts(List<Post> posts) {
        this.posts = posts;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    public List<UserAnswer> getUserAnswers() {
        return this.userAnswers;
    }

    public void setUserAnswers(List<UserAnswer> userAnswers) {
        this.userAnswers = userAnswers;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    public List<UserQuestion> getUserQuestions() {
        return this.userQuestions;
    }

    public void setUserQuestions(List<UserQuestion> userQuestions) {
        this.userQuestions = userQuestions;
    }

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "user")
    @Fetch (FetchMode.SELECT)
    public List<Answer> getAnswers() {
        return this.answers;
    }

    public void setAnswers(List<Answer> answers) {
        this.answers = answers;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    public List<UserPost> getUserPosts() {
        return this.userPosts;
    }

    public void setUserPosts(List<UserPost> userPosts) {
        this.userPosts = userPosts;
    }

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "user")
    @Fetch (FetchMode.SELECT)
    public List<Question> getQuestions() {
        return this.questions;
    }

    public void setQuestions(List<Question> questions) {
        this.questions = questions;
    }

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "user")
    @Fetch (FetchMode.SELECT)
    public List<Comment> getComments() {
        return this.comments;
    }

    public void setComments(List<Comment> comments) {
        this.comments = comments;
    }

}
